%my_1DBoxFilterDFT preforms a 1D box filter in frequency space.
%nf the function in the 1D spatial domain
%w the radius of the box filter (overall filter size: w+1+w)  
function [ dnf ] = my_1DBoxFilterDFT( nf, w )
 
N = size(nf,2);
area = (2*w+1)^2;
mult = 1/area;

%Concatenate the vector 2*w more times to a vector of zeroes
f = my_dft1D(nf);
m = f;
for i = 1:2*w
   m = [m;f]; 
end

%m(w+1,:) = f(:);

%Mean filter
for k = 1:N
    avg = 0;
    start_j = k-w;
    end_j = k+w;
    
    if start_j < 1
        start_j = 1;
    end
    if end_j > N
        end_j = N;
    end
    
   for i = 1:2*w+1
      for j = start_j:end_j
         avg = avg + mult*m(i,j);
      end
   end
   
   %Filtered value
   dnf(k) = avg;
   
end

%dnf = my_idft1D(dnf);
    
end

